package com.sparrow.manage.common.dao;

import com.sparrow.manage.common.entity.Attachment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface AttachmentDao extends JpaRepository<Attachment, String> {
    List<Attachment> queryByRelateId(String id);

    @Query(value = "delete from tb_attachment where relate_id = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void deleteByRelateId(String id);

    @Query(value = "from Attachment where relateId in ?1")
    List<Attachment> queryByRelateIds(String[] toArray);
}
